/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package usuario.control;

import bibliinfo.FrameMain;
import javax.swing.JOptionPane;
import usuario.model.Usuario;
import usuario.model.UsuarioDao;

/**
 *
 * @author Ar0n
 */
public class UserFrameDadosAddExcluir extends javax.swing.JInternalFrame {

    /**
     * Creates new form UserFrameDadosAddExcluir
     */
    public UserFrameDadosAddExcluir() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBExcluir = new javax.swing.JButton();

        jBExcluir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365288027_button_cancel.png"))); // NOI18N
        jBExcluir.setText("Deletar");
        jBExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBExcluirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jBExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 28, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBExcluirActionPerformed
        int i = JOptionPane.showConfirmDialog(FrameMain.userFrameAdd, "<html>Você realmente deseja <b color=\"red\">deletar</b> este usuário?</html>", "Deletar Usuário", 0);                
        if(i == 0){
            Usuario user = new Usuario();
            user.setRg(FrameMain.userFrameDados.getRgAntigo());
            user.setAtivo(false);
            UsuarioDao dao = new UsuarioDao();
            dao.delete(user);        
            JOptionPane.showMessageDialog(FrameMain.userFrameAdd, "<html>O usuário foi <b color=\"red\">deletado</b> com sucesso!</html>", "Sucesso", 1);
            
            FrameMain.userFrameAdd.setVisible(false);
            FrameMain.userFrameAdd.setEstado(false);
            
            FrameMain.userFrameMain.setVisible(true);
            FrameMain.userFrameMain.setEstado(true);
            FrameMain.formata(11);
        }        
    }//GEN-LAST:event_jBExcluirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jBExcluir;
    // End of variables declaration//GEN-END:variables
}
